package cn.devil.two.data

import cn.devil.two.utils.{CheckArguments, JedisUtil, SCUtiles}
import org.apache.spark.SparkContext
import org.apache.spark.rdd.RDD
import redis.clients.jedis.Jedis

object Data {
  def main(args: Array[String]): Unit = {
    CheckArguments(args,1,"请输入读取数据的文件",this.getClass)
    val Array(inputFilePath) = args
    val sc: SparkContext = SCUtiles.createSparkContextInstance("业务逻辑")
    val sqlContext = SCUtiles.createSQLContextInstance(sc)
    val data: RDD[String] = sc.textFile(inputFilePath)
    val dataLast = data.map(d => {
      val splits: Array[String] = d.split("\t")
      val appName = splits(1)
      (appName, splits)
    })
    /* val jedis: Jedis = JedisUtil.getJedis
          it.foreach(t=>{
            jedis.hincrBy("orchid-"+t._1,"total",t._2._1)
            jedis.hincrBy("orchid-"+t._1,"success",t._2._2)
            jedis.hincrByFloat("orchid-"+t._1,"money",t._2._3)
            jedis.hincrBy("orchid-"+t._1,"time",t._2._4)
          })
          println("ouput redis success")
          jedis.close()*/
    dataLast.foreachPartition(mp=>{
      val jedis: Jedis = JedisUtil.getJedis
      mp.foreach(f=>{
        jedis.hset(f._1,"appName",f._2.toString)
      })
    })
  }
}
